package com.example.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.example.item.ItemList;
import com.example.smsbox.R;

public class ContactAdapter extends ArrayAdapter<ItemList> {
	private LayoutInflater inflater;

	public ContactAdapter(Context context, int textViewResourceId,
			List<ItemList> objects) {
		super(context, textViewResourceId, objects);
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ItemList contact = this.getItem(position);
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.rowcontact, null);
			holder.txtName = (TextView) convertView
					.findViewById(R.id.textView1);
			holder.txtPhone = (TextView) convertView
					.findViewById(R.id.textView2);
			holder.checkBox = (CheckBox) convertView.findViewById(R.id.checkBox1);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.txtName.setText(contact.getHoten());
		holder.txtPhone.setText(contact.getSodienthoai());
		holder.checkBox.setChecked(contact.isChecked());
		return convertView;
	}

	private class ViewHolder {
		private TextView txtName;
		private TextView txtPhone;
		private CheckBox checkBox;
	}
}
